package by.epam.trenings.vkphotorest.content.database;

import com.google.gson.Gson;

import by.epam.trenings.vkphotorest.content.bo.AlbumModel;
import by.epam.trenings.vkphotorest.content.contract.TaskContract;
import android.content.ContentValues;

public class AlbumsTable {

	public AlbumsTable() {

	}

	/** The Constant COOKIE_TABLE. */
	public static final String ALBUMS_TABLE = "ALBUMS";

	/** The Constant COOKIE_COLUMNS. */
	public static final String[] ALBUMS_COLUMNS = {
			TaskContract.AlbumsColumns.ALBUM_ID,
			TaskContract.AlbumsColumns.CREATED,
			TaskContract.AlbumsColumns.DESCRIPTION,
			TaskContract.AlbumsColumns.SERVER_ID,
			TaskContract.AlbumsColumns.OWNER_ID,
			TaskContract.AlbumsColumns.PRIVACY,
			TaskContract.AlbumsColumns.SIZE,
			TaskContract.AlbumsColumns.THUMB_ID,
			TaskContract.AlbumsColumns.TITLE,
			TaskContract.AlbumsColumns.UPDATED,
			TaskContract.AlbumsColumns.THUMB_SRC };

	/** The Constant ALBUM_ID_COL_INDEX. */
	public static final int ALBUM_ID_COL_INDEX = 0;

	/** The Constant CREATED_COL_INDEX. */
	public static final int CREATED_COL_INDEX = 1;

	/** The Constant DESCRIPTION_COL_INDEX. */
	public static final int DESCRIPTION_COL_INDEX = 2;

	/** The Constant SERVER_ID_COL_INDEX. */
	public static final int ID_COL_INDEX = 3;

	/** The Constant OWNER_ID_COL_INDEX. */
	public static final int OWNER_ID_COL_INDEX = 4;

	/** The Constant PRIVACY_COL_INDEX. */
	public static final int PRIVACY_COL_INDEX = 5;

	/** The Constant SIZE_COL_INDEX. */
	public static final int SIZE_COL_INDEX = 6;

	/** The Constant THUMB_ID_COL_INDEX. */
	public static final int THUMB_ID_COL_INDEX = 7;

	/** The Constant TITLE_COL_INDEX. */
	public static final int TITLE_COL_INDEX = 8;

	/** The Constant UPDATED_COL_INDEX. */
	public static final int UPDATED_COL_INDEX = 9;

	/** The Constant THUMB_SRC_COL_INDEX. */
	public static final int THUMB_SRC_COL_INDEX = 10;

	/** The Constant CREATE_COOKIE_TABLE_SQL. */
	public static final String CREATE_ALBUMS_TABLE_SQL = "CREATE TABLE "
			+ ALBUMS_TABLE + " (" + ALBUMS_COLUMNS[ALBUM_ID_COL_INDEX]
			+ " INTEGER PRIMARY KEY AUTOINCREMENT, "
			+ ALBUMS_COLUMNS[CREATED_COL_INDEX] + " INTEGER, "
			+ ALBUMS_COLUMNS[DESCRIPTION_COL_INDEX] + " TEXT, "
			+ ALBUMS_COLUMNS[ID_COL_INDEX] + " INTEGER, "
			+ ALBUMS_COLUMNS[OWNER_ID_COL_INDEX] + " INTEGER, "
			+ ALBUMS_COLUMNS[PRIVACY_COL_INDEX] + " INTEGER, "
			+ ALBUMS_COLUMNS[SIZE_COL_INDEX] + " INTEGER, "
			+ ALBUMS_COLUMNS[THUMB_ID_COL_INDEX] + " INTEGER, "
			+ ALBUMS_COLUMNS[TITLE_COL_INDEX] + " TEXT, "
			+ ALBUMS_COLUMNS[UPDATED_COL_INDEX] + " INTEGER, "
			+ ALBUMS_COLUMNS[THUMB_SRC_COL_INDEX] + " TEXT)";

	/** The Constant DROP_COOKIE_TABLE_SQL. */
	public static final String DROP_ALBUMS_TABLE_SQL = "DROP TABLE IF EXISTS "
			+ ALBUMS_TABLE;

	public static ContentValues getContentValues(String album) {
		AlbumModel albumDeserialised = new Gson().fromJson(album,
				AlbumModel.class);
		ContentValues values = new ContentValues();
		values.put(ALBUMS_COLUMNS[AlbumsTable.CREATED_COL_INDEX],
				albumDeserialised.getCreated());
		values.put(ALBUMS_COLUMNS[AlbumsTable.DESCRIPTION_COL_INDEX],
				albumDeserialised.getDescription());
		values.put(ALBUMS_COLUMNS[AlbumsTable.OWNER_ID_COL_INDEX],
				albumDeserialised.getOwnerId());
		values.put(ALBUMS_COLUMNS[AlbumsTable.PRIVACY_COL_INDEX],
				albumDeserialised.getPrivacy());
		values.put(ALBUMS_COLUMNS[AlbumsTable.ID_COL_INDEX],
				albumDeserialised.getId());
		values.put(ALBUMS_COLUMNS[AlbumsTable.SIZE_COL_INDEX],
				albumDeserialised.getSize());
		values.put(ALBUMS_COLUMNS[AlbumsTable.THUMB_ID_COL_INDEX],
				albumDeserialised.getThumbId());
		values.put(ALBUMS_COLUMNS[AlbumsTable.THUMB_SRC_COL_INDEX],
				albumDeserialised.getThumbSrc());
		values.put(ALBUMS_COLUMNS[AlbumsTable.TITLE_COL_INDEX],
				albumDeserialised.getTitle());
		values.put(ALBUMS_COLUMNS[AlbumsTable.UPDATED_COL_INDEX],
				albumDeserialised.getUpdated());
		return values;
	}

}
